// Find all of the prime numbers between 2 and N
//

#include <iostream>
#include <format>
#include <cmath>

bool IsPrime(unsigned int n)
{
	// for (unsigned int i = 2; i <= n/2; ++i)
	for (unsigned int i = 2; i <= sqrtf(n*1.0f); ++i)
	{
		if (n % i == 0)
			return false;
	}

	return true;
}

int main()
{
	// output all of the prime numbers between 2 and 1M(1,000,000)
	int count = 0;
	for (unsigned int i = 2; i < 1e6; ++i)
	{	
		if (IsPrime(i)) {
			count++;
			std::cout << std::format("{:7}", i); // C++20

			// print 10 numbers per line
			if (count % 10 == 0)
				std::cout << std::endl;
		}
	}

	std::cout << std::endl;
	std::cout << "Total: " << count << std::endl;

	return 0;
}